package com.example.chapter;

import android.graphics.Color;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.example.chapter.util.DateUtil;

public class ButtonEnableActivity extends AppCompatActivity implements View.OnClickListener {

    public Button be_test;
    private TextView be_resule;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button_enable);

        Button be_enable = findViewById(R.id.be_enable);
        Button be_disable = findViewById(R.id.be_disable);
        be_test = findViewById(R.id.be_test);
        be_resule = findViewById(R.id.be_resule);

        be_enable.setOnClickListener(this);
        be_disable.setOnClickListener(this);
        be_test.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.be_enable:
                //启用当前控件
                be_test.setEnabled(true);
                //设置颜色
                be_test.setTextColor(Color.BLACK);
                break;

            case R.id.be_disable:
                //禁用当前控件
                be_test.setEnabled(false);
                //设置颜色
                be_test.setTextColor(Color.GRAY);
                break;

            case R.id.be_test:
                String desc = String.format("%s 您点击了按钮: %s", DateUtil.getNowTime(), ((Button) v).getText());
                be_resule.setText(desc);
                break;

            default:break;
        }
    }
}